package com.ourteam.system.api;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ourteam.frame.controller.AbstractServiceController;
import com.ourteam.frame.web.AbstractSearchHelper;
import com.ourteam.frame.web.AbstractTreeBuilderHelper;
import com.ourteam.frame.web.GridBean;
import com.ourteam.frame.web.TreeParamModel;
import com.ourteam.frame.web.TreeViewNodeBean;
import com.ourteam.system.dao.ISysDepartmentDAO;
import com.ourteam.system.dao.SysDepartmentDAOQueryBean;
import com.ourteam.system.dao.SysUserDAOQueryBean;
import com.ourteam.system.dao.SysUserDepartmentRelateDAOQueryBean;
import com.ourteam.system.domain.SysUserLoginLogBean;
import com.ourteam.system.domain.SystemDepartmentBean;
import com.ourteam.system.domain.SystemUserDepartmentRelateBean;
import com.ourteam.system.service.ISysDepartmentService;
import com.ourteam.system.service.ISysUserService;

@Controller
@CrossOrigin
@RequestMapping("/api/SYSTEM/SYSDEP")
public class SystemDepartmentAPI extends AbstractServiceController {

	/**
	 * 查询树结构
	 */
	@Autowired
	private ISysDepartmentService sysDepartmentService;

	@Autowired
	private ISysUserService sysUserService;

	// 系统部门
	@RequestMapping("/getSysDepartments")
	@ResponseBody
	public GridBean getSysDepartments(@ModelAttribute TreeParamModel treeParamModel) throws Exception {

		SystemDepartmentTreeBuilder treeBuilder = new SystemDepartmentTreeBuilder();

		AbstractTreeBuilderHelper<SystemDepartmentTreeBuilder> treeBuilderHelper = new AbstractTreeBuilderHelper<SystemDepartmentTreeBuilder>(
				treeBuilder) {

			@Override
			protected Object getInitParameter() {
				return null;
			}

		};

		return treeBuilderHelper.buildTree(treeParamModel);
	}

	@RequestMapping("/getSystemDepTreeSelect")
	@ResponseBody
	public TreeViewNodeBean[] getSystemDepTreeSelect() throws Exception {

		List<TreeViewNodeBean> treeNodeBeans = new ArrayList<TreeViewNodeBean>();

		SysDepartmentDAOQueryBean queryBean = new SysDepartmentDAOQueryBean();

		queryBean.createCriteria().andParentIdEqualTo(0);

		queryBean.setSortProperty(ISysDepartmentDAO.SortIndex);

		SystemDepartmentBean[] departmentBeans = sysDepartmentService.querySystemDepartments(queryBean);

		for (int i = 0; i < departmentBeans.length; i++) {

			SystemDepartmentBean departmentBean = departmentBeans[i];

			TreeViewNodeBean nodeBean = new TreeViewNodeBean();

			nodeBean.setNodeData(departmentBean);

			nodeBean.setId(String.valueOf(departmentBean.getId()));

			nodeBean.setText(departmentBean.getDepartmentName());

			getSystemDeps(departmentBean.getId(), nodeBean);

			treeNodeBeans.add(nodeBean);
		}

		return treeNodeBeans.toArray(new TreeViewNodeBean[treeNodeBeans.size()]);
	}

	protected void getSystemDeps(long parentId, TreeViewNodeBean treeNodeBean) throws Exception {

		SysDepartmentDAOQueryBean queryBean = new SysDepartmentDAOQueryBean();

		queryBean.createCriteria().andParentIdEqualTo(parentId);

		queryBean.setSortProperty(ISysDepartmentDAO.SortIndex);

		SystemDepartmentBean[] departmentBeans = sysDepartmentService.querySystemDepartments(queryBean);

		List<TreeViewNodeBean> children = new ArrayList<>();

		for (int i = 0; i < departmentBeans.length; i++) {

			SystemDepartmentBean departmentBean = departmentBeans[i];

			TreeViewNodeBean nodeBean = new TreeViewNodeBean();

			nodeBean.setNodeData(departmentBean);

			nodeBean.setId(String.valueOf(departmentBean.getId()));

			nodeBean.setText(departmentBean.getDepartmentName());

			getSystemDeps(departmentBean.getId(), nodeBean);

			children.add(nodeBean);
		}
		treeNodeBean.setNodes(children.toArray(new TreeViewNodeBean[children.size()]));
	}

	/**
	 * 删除系统部门
	 */
	@RequestMapping("/deleteSysDep")
	@ResponseBody
	public String deleteSysDep(@RequestParam(value = "id") long id, HttpServletRequest request, Model model)
			throws Exception {

		long ids[] = new long[1];

		ids[0] = id;

		SysUserDepartmentRelateDAOQueryBean queryBean = new SysUserDepartmentRelateDAOQueryBean();

		queryBean.createCriteria().andSysDepartmentIdEqualTo(id);

		String retString = "success";

		if (sysDepartmentService.querySystemUserDepartments(queryBean).length > 0) {

			retString = "error";

		} else {

			this.sysDepartmentService.deleteSystemDepartments(ids, getLoginUserId());

			retString = "success";
		}

		return retString;

	}

	/**
	 * 添加部门
	 */
	@RequestMapping("/saveDep")
	@ResponseBody
	public SystemDepartmentBean saveDep(@ModelAttribute SystemDepartmentBean systemDepartmentBean,
			HttpServletRequest request, Model model) throws Exception {

		systemDepartmentBean.setOperatorId(getLoginUserId());
		systemDepartmentBean.setModifyTime(new Date());

		if (systemDepartmentBean.getId() != 0) {

			sysDepartmentService.modifySystemDepartment(systemDepartmentBean);

		} else {

			sysDepartmentService.addNewSystemDepartment(systemDepartmentBean);
		}

		return systemDepartmentBean;
	}

	@RequestMapping("/saveUpsertakerDep")
	@ResponseBody
	public SystemDepartmentBean saveUpsertakerDep(@ModelAttribute SystemDepartmentBean systemDepartmentBean,
			HttpServletRequest request, Model model) throws Exception {

		if (systemDepartmentBean.getId() != 0) {

			sysDepartmentService.modifySystemDepartment(systemDepartmentBean);

		} else {
			SysUserLoginLogBean login = (SysUserLoginLogBean) request.getSession().getAttribute("loginUser");
			SysUserDepartmentRelateDAOQueryBean depUserQueryBean = new SysUserDepartmentRelateDAOQueryBean();
			depUserQueryBean.createCriteria().andSysUserIdEqualTo(login.getUserId());
			SystemUserDepartmentRelateBean[] sysUserDepartmentRelate;
			sysUserDepartmentRelate = sysDepartmentService.querySystemUserDepartments(depUserQueryBean);
			systemDepartmentBean.setParentId(sysUserDepartmentRelate[0].getSysDepartmentId());

			sysDepartmentService.addNewSystemDepartment(systemDepartmentBean);

		}

		return systemDepartmentBean;
	}

	/**
	 * 根据id查询对象
	 */
	@RequestMapping("/getSysDepartmentById")
	@ResponseBody
	public SystemDepartmentBean getSysDepartmentById(@RequestParam(value = "id", required = true) long id,
			HttpServletRequest request, Model model) throws Exception {

		return sysDepartmentService.getSystemDepartmentById(id);

	}

	/**
	 * 根据id查询对象
	 */
	@RequestMapping("/getSysDepUserById")
	@ResponseBody
	public SystemUserDepartmentRelateBean getSysDepUserById(@RequestParam(value = "id", required = true) long id,
			HttpServletRequest request, Model model) throws Exception {

		return sysDepartmentService.getSystemUserDepartmentById(id);

	}

	@RequestMapping("/getUserDepartmentByUserId")
	@ResponseBody
	public SystemUserDepartmentRelateBean[] getUserDepartmentByUserId(
			@RequestParam(value = "id", required = true) long id, HttpServletRequest request, Model model)
			throws Exception {

		SysUserDepartmentRelateDAOQueryBean queryBean = new SysUserDepartmentRelateDAOQueryBean();

		queryBean.createCriteria().andSysUserIdEqualTo(id);

		return sysDepartmentService.querySystemUserDepartments(queryBean);

	}

	@RequestMapping("/queryDepList")
	@ResponseBody
	public GridBean queryDepList(@ModelAttribute SystemDepSearchModel searchModel, HttpServletRequest request,
			Model model) throws Exception {

		AbstractSearchHelper<SysDepartmentDAOQueryBean, SystemDepSearchModel> searchHelper = new AbstractSearchHelper<SysDepartmentDAOQueryBean, SystemDepSearchModel>(
				searchModel) {

			@Override
			protected int queryCount(SysDepartmentDAOQueryBean queryBean) throws Exception {
				queryBean.createCriteria().andDepartmentNameEqualTo("承办单位");

				SystemDepartmentBean[] sysDepartments = sysDepartmentService.querySystemDepartments(queryBean);
				Long[] depIds = new Long[sysDepartments.length];
				for (int i = 0; i < sysDepartments.length; i++) {
					depIds[i] = sysDepartments[i].getId();
				}
				SysDepartmentDAOQueryBean queryBean2 = new SysDepartmentDAOQueryBean();
				queryBean2.createCriteria().andParentIdIn(depIds);
				sysDepartments = sysDepartmentService.querySystemDepartments(queryBean2);
				depIds = null;
				depIds = new Long[sysDepartments.length];
				for (int i = 0; i < sysDepartments.length; i++) {
					depIds[i] = sysDepartments[i].getId();
				}
				// getSystemDep(sysDepartments[0].getId(),"--",
				// systemDepartments);
				SysDepartmentDAOQueryBean queryBean3 = new SysDepartmentDAOQueryBean();
				queryBean3.createCriteria().andParentIdIn(depIds);
				return sysDepartmentService.querySystemDepartmentCount(queryBean3);
			}

			@Override
			protected Object[] queryData(SysDepartmentDAOQueryBean queryBean) throws Exception {
				queryBean.createCriteria().andDepartmentNameEqualTo("承办单位");

				SystemDepartmentBean[] sysDepartments = sysDepartmentService.querySystemDepartments(queryBean);
				Long[] depIds = new Long[sysDepartments.length];
				for (int i = 0; i < sysDepartments.length; i++) {
					depIds[i] = sysDepartments[i].getId();
				}
				SysDepartmentDAOQueryBean queryBean2 = new SysDepartmentDAOQueryBean();
				queryBean2.createCriteria().andParentIdIn(depIds);
				sysDepartments = sysDepartmentService.querySystemDepartments(queryBean2);
				depIds = null;
				depIds = new Long[sysDepartments.length];
				for (int i = 0; i < sysDepartments.length; i++) {
					depIds[i] = sysDepartments[i].getId();
				}
				// getSystemDep(sysDepartments[0].getId(),"--",
				// systemDepartments);
				SysDepartmentDAOQueryBean queryBean3 = new SysDepartmentDAOQueryBean();
				queryBean3.createCriteria().andParentIdIn(depIds);
				return sysDepartmentService.querySystemDepartments(queryBean3);
			}

			@Override
			protected SysDepartmentDAOQueryBean createQueryBean() {

				return new SysDepartmentDAOQueryBean();
			}
		};
		return searchHelper.doSearch(request);

	}

	@RequestMapping("/querySysUserNotInDepList")
	@ResponseBody
	public GridBean querySysUserNotInDepList(@RequestParam long depId,
			@ModelAttribute SystemAccountSearchModel searchModel, HttpServletRequest request, Model model)
			throws Exception {

		if (depId != 0) {

			// 根据部门id查询部门关系
			SysUserDepartmentRelateDAOQueryBean queryBean = new SysUserDepartmentRelateDAOQueryBean();

			queryBean.createCriteria().andSysDepartmentIdEqualTo(depId);

			SystemUserDepartmentRelateBean[] systemUserDepartmentRelate = sysDepartmentService
					.querySystemUserDepartments(queryBean);

			long userids[] = new long[systemUserDepartmentRelate.length + 1];

			for (int i = 0; i < systemUserDepartmentRelate.length; i++) {

				userids[i] = systemUserDepartmentRelate[i].getSysUserId();

			}

			searchModel.setExcludeIds(userids);

		}

		AbstractSearchHelper<SysUserDAOQueryBean, SystemAccountSearchModel> searchHelper = new AbstractSearchHelper<SysUserDAOQueryBean, SystemAccountSearchModel>(
				searchModel) {

			@Override
			protected int queryCount(SysUserDAOQueryBean queryBean) throws Exception {

				return sysUserService.getSysUserCount(queryBean);
			}

			@Override
			protected Object[] queryData(SysUserDAOQueryBean queryBean) throws Exception {

				return sysUserService.getSysUsers(queryBean);
			}

			@Override
			protected SysUserDAOQueryBean createQueryBean() {

				return new SysUserDAOQueryBean();
			}

		};
		return searchHelper.doSearch(request);

	}

	@RequestMapping("/querySysDepRelatedUserList")
	@ResponseBody
	public GridBean querySysDepRelatedUserList(@RequestParam(value = "id", required = true) final long id,
			@ModelAttribute SystemDepUserSearchModel searchModel, HttpServletRequest request, Model model)
			throws Exception {

		AbstractSearchHelper<SysUserDepartmentRelateDAOQueryBean, SystemDepUserSearchModel> searchHelper = new AbstractSearchHelper<SysUserDepartmentRelateDAOQueryBean, SystemDepUserSearchModel>(
				searchModel) {

			@Override
			protected int queryCount(SysUserDepartmentRelateDAOQueryBean queryBean) throws Exception {
				SysUserDepartmentRelateDAOQueryBean qb = new SysUserDepartmentRelateDAOQueryBean();

				qb.createCriteria().andSysDepartmentIdEqualTo(id);

				return sysDepartmentService.querySystemUserDepartmentCount(qb);
			}

			@Override
			protected Object[] queryData(SysUserDepartmentRelateDAOQueryBean queryBean) throws Exception {
				SysUserDepartmentRelateDAOQueryBean qb = new SysUserDepartmentRelateDAOQueryBean();

				qb.createCriteria().andSysDepartmentIdEqualTo(id);

				return sysDepartmentService.querySystemUserDepartments(qb);
			}

			@Override
			protected SysUserDepartmentRelateDAOQueryBean createQueryBean() {

				return new SysUserDepartmentRelateDAOQueryBean();
			}
		};

		return searchHelper.doSearch(request);

	}

	/**
	 * 根据部门关系表查出所有人员 1.根据部门编号查询部门关系表，没有id就查询全部 2.查询部门关系表查出所有人员用集合或数组存储
	 * 3.根据人员的数组查询出人员列表
	 */
	@RequestMapping("/getSysUserDepartment")
	@ResponseBody
	public SysUserDAOQueryBean getSysUserDepNotIn(long id) throws Exception {

		// 根据部门id查询部门关系
		SysUserDepartmentRelateDAOQueryBean queryBean = new SysUserDepartmentRelateDAOQueryBean();

		if (id != 0) {

			queryBean.createCriteria().andSysDepartmentIdEqualTo(id);

		}

		SystemUserDepartmentRelateBean[] systemUserDepartmentRelate = sysDepartmentService
				.querySystemUserDepartments(queryBean);

		long userids[] = new long[systemUserDepartmentRelate.length + 1];

		for (int i = 0; i < systemUserDepartmentRelate.length; i++) {

			userids[i] = systemUserDepartmentRelate[i].getSysUserId();

		}

		SysUserDAOQueryBean qb1 = new SysUserDAOQueryBean();

		qb1.createCriteria().andUserTypeNotEqualToOrIsNull("admin").andIdNotIn(userids);

		return qb1;
	}

	/**
	 * 根据部门关系表查出所有人员 1.根据部门编号查询部门关系表，没有id就查询全部 2.查询部门关系表查出所有人员用集合或数组存储
	 * 3.根据人员的数组查询出人员列表
	 */
	public SysUserDAOQueryBean getSysUserDepIn(long id) throws Exception {

		// 根据部门id查询部门关系
		SysUserDepartmentRelateDAOQueryBean queryBean = new SysUserDepartmentRelateDAOQueryBean();

		if (id != 0) {

			queryBean.createCriteria().andSysDepartmentIdEqualTo(id);

		}

		SystemUserDepartmentRelateBean[] systemUserDepartmentRelate = sysDepartmentService
				.querySystemUserDepartments(queryBean);

		long userids[] = new long[systemUserDepartmentRelate.length + 1];

		for (int i = 0; i < systemUserDepartmentRelate.length; i++) {

			userids[i] = systemUserDepartmentRelate[i].getSysUserId();

		}

		SysUserDAOQueryBean qb1 = new SysUserDAOQueryBean();

		qb1.createCriteria().andUserTypeNotEqualToOrIsNull("admin").andIdIn(userids);

		return qb1;
	}

	@RequestMapping("/querySysDepAccountList")
	@ResponseBody
	public GridBean querySysAccountByDepIds(@RequestParam(value = "id", required = true) final long id,
			@ModelAttribute SystemAccountSearchModel searchModel, HttpServletRequest request, Model model)
			throws Exception {

		AbstractSearchHelper<SysUserDAOQueryBean, SystemAccountSearchModel> searchHelper = new AbstractSearchHelper<SysUserDAOQueryBean, SystemAccountSearchModel>(
				searchModel) {

			@Override
			protected int queryCount(SysUserDAOQueryBean queryBean) throws Exception {

				return sysUserService.getSysUserCount(getSysUserDepIn(id));
			}

			@Override
			protected Object[] queryData(SysUserDAOQueryBean queryBean) throws Exception {

				return sysUserService.getSysUsers(getSysUserDepIn(id));
			}

			@Override
			protected SysUserDAOQueryBean createQueryBean() {

				return new SysUserDAOQueryBean();
			}
		};

		return searchHelper.doSearch(request);

	}

	// 添加人员部门
	/**
	 * 添加部门
	 */
	@RequestMapping("/saveDepUser")
	@ResponseBody
	public SystemUserDepartmentRelateBean saveDepUser(@RequestParam(value = "uid", required = true) String userId,
			@RequestParam(value = "depId", required = true) long depId,
			@ModelAttribute SystemUserDepartmentRelateBean systemUserDepartmentRelateBean, HttpServletRequest request,
			Model model) throws Exception {

		String userIds[] = userId.split(",");

		for (int i = 0; i < userIds.length; i++) {

			SystemUserDepartmentRelateBean bean = new SystemUserDepartmentRelateBean();

			bean.setSysDepartmentId(depId);

			bean.setSysUserId(Long.parseLong(userIds[i]));

			sysDepartmentService.setSystemUserDepartment(bean);

		}

		return systemUserDepartmentRelateBean;
	}

	/**
	 * 删除系统部门
	 */
	@RequestMapping("/deleteSysDepUser")
	@ResponseBody
	public String deleteSysDepUser(@RequestParam(value = "ids") long[] ids, HttpServletRequest request, Model model)
			throws Exception {

		this.sysDepartmentService.deleteSystemUserDepartments(ids);

		return "success";
	}

	/**
	 * 删除系统部门
	 */
	@RequestMapping("/deleteUndertakerDepUser")
	@ResponseBody
	public String deleteUndertakerDepUser(@RequestParam(value = "id") String id, HttpServletRequest request,
			Model model) throws Exception {

		String[] idString = id.split(",");

		long ids[] = new long[idString.length];

		for (int i = 0; i < idString.length; i++) {

			ids[i] = Long.parseLong(idString[i]);

		}

		SysUserDepartmentRelateDAOQueryBean queryBean = new SysUserDepartmentRelateDAOQueryBean();

		queryBean.createCriteria().andIdIn(ids);

		SystemUserDepartmentRelateBean[] systemUserDepartmentRelateBean = sysDepartmentService
				.querySystemUserDepartments(queryBean);

		long uids[] = new long[systemUserDepartmentRelateBean.length];

		for (int i = 0; i < systemUserDepartmentRelateBean.length; i++) {

			uids[0] = systemUserDepartmentRelateBean[i].getSysUserId();

		}

		this.sysUserService.deleteSysUsers(uids, getLoginUserId());

		this.sysDepartmentService.deleteSystemUserDepartments(ids);

		return "success";
	}

	/**
	 * 添加部门成员
	 */
	@RequestMapping("/addDepUsers")
	@ResponseBody
	public boolean addDepUsers(@RequestParam long depId, @RequestParam(value = "userIds") long[] userIds,
			HttpServletRequest request, Model model) throws Exception {

		for (int i = 0; i < userIds.length; i++) {
			SystemUserDepartmentRelateBean aSystemUserDepartment = new SystemUserDepartmentRelateBean();
			aSystemUserDepartment.setSysDepartmentId(depId);
			aSystemUserDepartment.setSysUserId(userIds[i]);
			aSystemUserDepartment.setDepartmentRole("member");
			this.sysDepartmentService.setSystemUserDepartment(aSystemUserDepartment);
		}

		return true;
	}

	@RequestMapping("/setUserDepartment")
	@ResponseBody
	public boolean setUserDepartment(@RequestParam long userId, @RequestParam long depId, @RequestParam String depRole,
			HttpServletRequest request, Model model) throws Exception {

		SystemUserDepartmentRelateBean aSystemUserDepartment = new SystemUserDepartmentRelateBean();
		aSystemUserDepartment.setSysDepartmentId(depId);
		aSystemUserDepartment.setSysUserId(userId);
		aSystemUserDepartment.setDepartmentRole(depRole);
		this.sysDepartmentService.setSystemUserDepartment(aSystemUserDepartment);

		return true;
	}

	/**
	 * 添加部门成员
	 */
	@RequestMapping("/setDepManagers")
	@ResponseBody
	public boolean setDepManagers(@RequestParam long depId, @RequestParam(value = "ids") long[] userIds,
			HttpServletRequest request, Model model) throws Exception {

		for (int i = 0; i < userIds.length; i++) {
			SystemUserDepartmentRelateBean aSystemUserDepartment = this.sysDepartmentService
					.getSystemUserDepartmentById(userIds[i]);

			if (aSystemUserDepartment == null) {
				aSystemUserDepartment = new SystemUserDepartmentRelateBean();
			}
			aSystemUserDepartment.setSysDepartmentId(aSystemUserDepartment.getSysDepartmentId());
			aSystemUserDepartment.setSysUserId(aSystemUserDepartment.getSysUserId());
			aSystemUserDepartment.setDepartmentRole("manager");
			this.sysDepartmentService.setSystemUserDepartment(aSystemUserDepartment);
		}

		return true;
	}

	/**
	 * 添加部门成员
	 */
	@RequestMapping("/setDepUserRoles")
	@ResponseBody
	public boolean setDepUserRoles(@RequestParam long depId, @RequestParam(value = "ids") long[] userIds,
			@RequestParam String role, HttpServletRequest request, Model model) throws Exception {

		for (int i = 0; i < userIds.length; i++) {
			SystemUserDepartmentRelateBean aSystemUserDepartment = this.sysDepartmentService
					.getSystemUserDepartmentById(userIds[i]);

			if (aSystemUserDepartment == null) {
				aSystemUserDepartment = new SystemUserDepartmentRelateBean();
			}
			aSystemUserDepartment.setSysDepartmentId(aSystemUserDepartment.getSysDepartmentId());
			aSystemUserDepartment.setSysUserId(aSystemUserDepartment.getSysUserId());
			aSystemUserDepartment.setDepartmentRole(role);
			this.sysDepartmentService.setSystemUserDepartment(aSystemUserDepartment);
		}

		return true;
	}

	@RequestMapping("/moveUpDepartment")
	@ResponseBody
	public String moveUpDepartment(@RequestParam long depId, HttpServletRequest request, Model model) throws Exception {

		SystemDepartmentBean departmentBean = this.sysDepartmentService.getSystemDepartmentById(depId);

		if (departmentBean.getSortIndex() > 1) {
			sysDepartmentService.setSystemDepartmentSortIndex(depId, departmentBean.getSortIndex() - 1,
					getLoginUserId());
		}

		return "success";
	}

	@RequestMapping("/moveDownDepartment")
	@ResponseBody
	public String moveDownDepartment(@RequestParam long depId, HttpServletRequest request, Model model)
			throws Exception {

		SystemDepartmentBean departmentBean = this.sysDepartmentService.getSystemDepartmentById(depId);

		int totalCount = sysDepartmentService.getMaxSystemDepartmentSortIndex(departmentBean.getParentId());

		if (departmentBean.getSortIndex() < totalCount) {
			sysDepartmentService.setSystemDepartmentSortIndex(depId, departmentBean.getSortIndex() + 1,
					getLoginUserId());
		}

		return "success";
	}
}
